package com.dyylearn.pkg.encap;

public class Account {
    private String name;
    private double balance;
    private String password;

    public Account() {
    }

    public Account(String name, double balance, String password) {
        setName(name);
        setBalance(balance);
        setPassword(password);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
       if(name.length() >= 2 && name.length() <= 4) {
           this.name = name;
       } else {
           System.out.println("名字长度为2~4位, 默认值无名");
           name = "无名";
       }
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        if(balance > 20) {
            this.balance = balance;
        } else {
            System.out.println("余额必须>20，默认为0");
        }
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        if(password.length() == 6) {
            this.password = password;
        } else {
            System.out.println("密码必须是6位，默认为000000");
            this.password = "000000";
        }
    }

    //显示账号信息
    public void showInfo() {
            System.out.println("账号信息 name=" + name + " 余额=" + balance + " 密码=" + password);

        //可以增加权限的校验
//        if() {
//            System.out.println("账号信息 name=" + name + " 余额=" + balance + " 密码=" + password);
//        } else {
//            System.out.println("你无权查看");
//        }
    }
}
